//
//  RecommendHotelDataHotCityTableCell.m
//  AroundTheWorld
//
//  Created by IfelseGo on 16/5/24.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "RecommendHotelDataHotCityTableCell.h"
#import "RecommendHotelDataHotCityCollectionCell.h"
#define WIDTH self.frame.size.width
#define HEIGHT self.frame.size.height

@implementation RecommendHotelDataHotCityTableCell
//自定义初始化
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addView];
        self.myArrayM = [NSMutableArray array];
    }
    return self;
}

- (void)addView
{
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.itemSize = CGSizeMake(WIDTH / 3, 55);
    flowLayout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    UICollectionView *collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, 0, 0) collectionViewLayout:flowLayout];
    
    collectionV.backgroundColor = [UIColor colorWithRed:251 / 255.0 green:248 / 255.0 blue:251 / 255.0 alpha:1.0];
    [self.contentView addSubview:collectionV];
    
    //成为代理人
    collectionV.delegate = self;
    collectionV.dataSource = self;
    
    //注册
    UINib *nib = [UINib nibWithNibName:@"RecommendHotelDataHotCityCollectionCell" bundle:[NSBundle mainBundle]];
    [collectionV registerNib:nib forCellWithReuseIdentifier:@"HotCollection"];
    self.myCollectionV = collectionV;
}
//cell数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 9;
}
//建cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RecommendHotelDataHotCityCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HotCollection" forIndexPath:indexPath];
    RecommendHotelDataCityModel *model = [self.myArrayM objectAtIndex:indexPath.row];
    cell.cnNameLabel.text = model.cnname;
    cell.enNameLabel.text = model.enname;
    return cell;
}

- (void)setMyArrayM:(NSMutableArray *)myArrayM
{
    _myArrayM = myArrayM;
    [self.myCollectionV reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.myCollectionV.frame = self.contentView.frame;
}

//点击触发方法

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//    SubjectModel *model = [self.subjectArray objectAtIndex:indexPath.row + 1];
//    self.myBlock(model.url, model.title);
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
